﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UserDefineForm.control;
using System.ComponentModel;
using System.Drawing;

namespace UserDefineForm.dao.orm
{
    public class ControlORM
    {
        #region properties

        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        private int formId=0;

        public int FormId
        {
            get { return formId; }
            set { formId = value; }
        }
        private string name="";

        private int type=0;

        public int Type
        {
            get { return type; }
            set { type = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private int width=0;

        public int Width
        {
            get { return width; }
            set { width = value; }
        }
        private int height=0;

        public int Height
        {
            get { return height; }
            set { height = value; }
        }
        private int top=0;

        public int Top
        {
            get { return top; }
            set { top = value; }
        }
        private int left=0;

        public int Left
        {
            get { return left; }
            set { left = value; }
        }
        private string font="";

        public string Font
        {
            get { return font; }
            set { font = value; }
        }
        private string defaultValue="";

        public string DefaultValue
        {
            get { return defaultValue; }
            set { defaultValue = value; }
        }
        private string tooltipText="";

        public string TooltipText
        {
            get { return tooltipText; }
            set { tooltipText = value; }
        }
        private int summaryField=0;

        public int SummaryField
        {
            get { return summaryField; }
            set { summaryField = value; }
        }
        private int status=0;

        public int Status
        {
            get { return status; }
            set { status = value; }
        }
        private int listIndexId=0;

        public int ListIndexId
        {
            get { return listIndexId; }
            set { listIndexId = value; }
        }

        private string value="";

        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
        
        
        #endregion

        public ControlORM()
        {

        }

        public ControlORM(DesignableControlBase control)
        {
            this.Id = control.Id;
            this.FormId = control.FormId;
            this.Name = control.Name;
            this.Top = control.Top;
            this.Left = control.Left;
            this.Width = control.Width;
            this.Height = control.Height;

            TypeConverter tc = TypeDescriptor.GetConverter(typeof(Font));
            this.Font = tc.ConvertToString(control.FontProp);

            this.value = control.Value;

            this.DefaultValue = control.DefaultValue;
            this.TooltipText = "";
            this.SummaryField = 0;
            this.Status = 0;
            this.ListIndexId = 0;

            if (control is DesignableCheckBox)
            {
                this.Type = (int)ControlType.CheckBox;
            }
            else if (control is DesignableComboBox)
            {
                this.Type = (int)ControlType.ComboBox;
            }
            else if (control is DesignableDatePicker)
            {
                this.Type = (int)ControlType.DatePicker;
            }
            else if (control is DesignableRadioButton)
            {
                this.Type = (int)ControlType.RadioButton;
            }
            else if (control is DesignableNumbericTextBox)
            {
                this.Type = (int)ControlType.NumberTextBox;
            }
            else
            {
                this.Type = (int)ControlType.TextBox;
            }

        }
        
        public DesignableControlBase toControl(SupplierFormGUI gui)
        {
            DesignableControlBase control;

            switch (this.Type)
            {
                case (int)ControlType.CheckBox:
                    control = new DesignableCheckBox(gui.designPanel, gui.propertiesPnl);
                    break;
                case (int)ControlType.ComboBox:
                    control = new DesignableComboBox(gui.designPanel, gui.propertiesPnl);
                    break;
                case (int)ControlType.DatePicker:
                    control = new DesignableDatePicker(gui.designPanel, gui.propertiesPnl);
                    break;
                case (int)ControlType.RadioButton:
                    control = new DesignableRadioButton(gui.designPanel, gui.propertiesPnl);
                    break;
                case (int)ControlType.TextBox:
                    control = new DesignableTextBox(gui.designPanel, gui.propertiesPnl);
                    break;
                case (int)ControlType.NumberTextBox:
                    control = new DesignableNumbericTextBox(gui.designPanel, gui.propertiesPnl);
                    break;
                default: 
                    return null;
            }

            control.Id=this.Id ;
            control.FormId=this.FormId ;
            control.Name=this.Name ;
            control.Top=this.Top ;
            control.Left=this.Left ;
            control.Width=this.Width ;
            control.Height=this.Height ;
            control.Value = this.Value;

            TypeConverter tc = TypeDescriptor.GetConverter(typeof(Font));
            control.FontProp= (Font)tc.ConvertFromString(this.Font);

            control.DefaultValue=this.DefaultValue ;
            //this.TooltipText = "";
            //=this.SummaryField = 0;
            //=this.Status = 0;
            //=this.ListIndexId = 0;

            return control;


        }
        
    
    }
}
